package com.hospital.workstation.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.hospital.common.annotation.RepeatSubmit;
import com.hospital.common.annotation.Log;
import com.hospital.common.core.controller.BaseController;
import com.hospital.common.core.domain.PageQuery;
import com.hospital.common.core.domain.R;
import com.hospital.common.core.validate.AddGroup;
import com.hospital.common.core.validate.EditGroup;
import com.hospital.common.core.validate.QueryGroup;
import com.hospital.common.enums.BusinessType;
import com.hospital.common.utils.poi.ExcelUtil;
import com.hospital.workstation.domain.vo.HisChangeDepartmentVo;
import com.hospital.workstation.domain.bo.HisChangeDepartmentBo;
import com.hospital.workstation.service.IHisChangeDepartmentService;
import com.hospital.common.core.page.TableDataInfo;

/**
 * 转科信息
 *
 * @author whb
 * @date 2023-03-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/workstation/changeDepartment")
public class HisChangeDepartmentController extends BaseController {

    private final IHisChangeDepartmentService iHisChangeDepartmentService;

    /**
     * 查询转科信息列表
     */
    @SaCheckPermission("workstation:changeDepartment:list")
    @GetMapping("/list")
    public TableDataInfo<HisChangeDepartmentVo> list(HisChangeDepartmentBo bo, PageQuery pageQuery) {
        return iHisChangeDepartmentService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询转科记录列表
     *
     * @param bo 转科业务对象
     * @return
     */
    @SaCheckPermission("workstation:changeDepartment:list2")
    @GetMapping("/list2")
    public R<List<HisChangeDepartmentVo>> queryList(HisChangeDepartmentBo bo) {
        return R.ok(iHisChangeDepartmentService.queryList(bo));
    }

    /**
     * 获取转科信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("workstation:changeDepartment:query")
    @GetMapping("/{id}")
    public R<HisChangeDepartmentVo> getInfo(@NotNull(message = "主键不能为空")
                                            @PathVariable Long id) {
        return R.ok(iHisChangeDepartmentService.queryById(id));
    }

    /**
     * 新增转科信息
     */
    @SaCheckPermission("workstation:changeDepartment:add")
    @Log(title = "转科信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HisChangeDepartmentBo bo) {
        return toAjax(iHisChangeDepartmentService.insertByBo(bo));
    }

    /**
     * 修改转科信息
     */
    @SaCheckPermission("workstation:changeDepartment:edit")
    @Log(title = "转科信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HisChangeDepartmentBo bo) {
        return toAjax(iHisChangeDepartmentService.updateByBo(bo));
    }

    /**
     * 删除转科信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("workstation:changeDepartment:remove")
    @Log(title = "转科信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iHisChangeDepartmentService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
